#include <algorithm>
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
#define int long long
 
signed main()
{
    // abs(e - k) <= p
    // if(e >= k) e - k <= p, e - p <= k 无语
    // if(e < k) k - e <= p, p - e >= k
    int n = 0, p = 0;
    cin >> n >> p;
    vector<int> arr(n);
    int arrMIN = INT_MAX, arrMAX = INT_MIN;
    for(int i = 0; i < n; ++i)
    {
        cin >> arr[i];
        // arrMIN = min(arrMIN, arr[i]);
        // arrMAX = max(arrMAX, arr[i]);
    }
    // sort(arr.begin(), arr.end());
    int res = INT_MIN;
    for(int k = -100; k < 100; ++k)
    {
        int cnt = 0;
        for(auto& e : arr)
        {
            if(abs(e - k) <= p)
                ++cnt;
        }
        // cout << k << " " << cnt << endl;
        res = max(res, cnt);
    }
    cout << res << endl;
    return 0;
}